'''
Created on 06/06/2012

@author: Administrador
'''
import unittest
from main.memory import PhysicalMemory, FirstAdjustment, BestAdjustment,WorstAdjustment 
from main.process import PCB, Instruction, ProcessStatus,IOInstruction

class TestMemory(unittest.TestCase):
    def setUp(self):
        self.memoria = PhysicalMemory(7,None)
        self.pcb1 =  PCB(3)
        self.pcb2 =  PCB(6)
        self.instruction1 =  IOInstruction(4,'Printer')
        self.instruction2 =  Instruction(ProcessStatus().IO,2)
        self.instruction3 =  Instruction(ProcessStatus().IO,3)
        self.instruction4 =  IOInstruction(4,'Printer')
        self.instruction5 =  Instruction(ProcessStatus().IO,5)
        self.instruction6 =  IOInstruction(4,'Printer')
        self.instruction7 =  Instruction(ProcessStatus().IO,7)


    def test_getTheBaseRegister_FA(self):
        self.memoria.addingPolicy = FirstAdjustment()
        self.memoria.cells[0] = self.instruction2
        self.memoria.cells[4] = self.instruction3
        x = self.memoria.addingPolicy.getTheBaseRegister(self.memoria, 2)
        self.assertTrue(1 == x)
        
        
    def test_getTheBaseRegister_BA(self):
        self.memoria.addingPolicy = BestAdjustment()
        self.memoria.cells[0] = self.instruction2
        self.memoria.cells[4] = self.instruction3
        x = self.memoria.addingPolicy.getTheBaseRegister(self.memoria, 2)
        self.assertTrue(5 == x)
        
        
    def test_getTheBaseRegister_WA(self):
        self.memoria.addingPolicy = WorstAdjustment()
        self.memoria.cells[0] = self.instruction2
        self.memoria.cells[4] = self.instruction3
        x = self.memoria.addingPolicy.getTheBaseRegister(self.memoria, 2)
        self.assertTrue(1 == x)


suite = unittest.TestLoader().loadTestsFromTestCase(TestMemory)
unittest.TextTestRunner(verbosity=2).run(suite)